<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/logo.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/logo.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/logo.png">
  <link rel="mask-icon" href="/images/logo.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/","scheme":"Pisces","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"./public/search.xml"};
  </script>

  <meta name="description" content="click look more">
<meta property="og:type" content="article">
<meta property="og:title" content="6.1">
<meta property="og:url" content="https://gitee.com/mamba666/mamba666.git/2020/06/01/6.1/index.html">
<meta property="og:site_name" content="共你云雨">
<meta property="og:description" content="click look more">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/images/27.png">
<meta property="og:image" content="https://gitee.com/images/28.png">
<meta property="og:image" content="https://gitee.com/images/29.png">
<meta property="article:published_time" content="2020-06-01T11:00:22.626Z">
<meta property="article:modified_time" content="2020-06-04T12:25:41.829Z">
<meta property="article:author" content="Edison">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/images/27.png">

<link rel="canonical" href="https://gitee.com/mamba666/mamba666.git/2020/06/01/6.1/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  <title>6.1 | 共你云雨</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>
	<a href="https://github.com/mamba666" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">共你云雨</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/mamba666/mamba666.git/2020/06/01/6.1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Edison">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="共你云雨">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          6.1
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-06-01 19:00:22" itemprop="dateCreated datePublished" datetime="2020-06-01T19:00:22+08:00">2020-06-01</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-06-04 20:25:41" itemprop="dateModified" datetime="2020-06-04T20:25:41+08:00">2020-06-04</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E9%9D%A2%E8%AF%95/" itemprop="url" rel="index"><span itemprop="name">面试</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>click look more</p>
<a id="more"></a>

<blockquote>
<p>加油</p>
</blockquote>
<h1 id="vueAPP适配怎么写，用了什么单位？"><a href="#vueAPP适配怎么写，用了什么单位？" class="headerlink" title="vueAPP适配怎么写，用了什么单位？"></a>vueAPP适配怎么写，用了什么单位？</h1><p>写过一个vue移动端的页面。样式方面适配的话使用了border.css来解决移动端一像素边框问题，reset.css用来重置默认样式。因为现在手极端都是两倍屏幕，所以rem使用的时候要除以2。</p>
<p>同时meta标签还写了 user-scalable=no(禁止缩放) initial、minimum、maximum-scale都设置为1</p>
<h1 id="get和post的区别？"><a href="#get和post的区别？" class="headerlink" title="get和post的区别？"></a>get和post的区别？</h1><p>这个问题可以单独写一篇博客了，但是还是在这里赘述一遍之后再去重新写，加深印象。</p>
<h2 id="http请求报文"><a href="#http请求报文" class="headerlink" title="http请求报文"></a>http请求报文</h2><p>既然要说get和post，就必不可少得提一嘴http请求报文。因为本质上get和post都是http的请求方法之一（其他的还有put、delete等）。简言之，get用来获取数据，post用来修改数据。</p>
<p>接下来说说报文结构，可以分为三个部分：请求行、请求头部、请求数据。如下图</p>
<p><img src="/images/27.png" alt></p>
<p>get请求示例： GET https://………com?key=xxx&amp;id=xxxx HTTP/1.1<br>post请求示例： POST HTTP/1.1</p>
<p>可以发现post请求是没有url的，他的url在请求数据中</p>
<h2 id="get方法的特点"><a href="#get方法的特点" class="headerlink" title="get方法的特点"></a>get方法的特点</h2><ol>
<li>使用？分割url和传输数据，使用&amp;连接多个传输数据</li>
<li>具有安全性和幂等性：指的是非修改信息，即该操作用于获取信息而非修改信息。换句话说，GET 请求一般不应产生副作用，也就是说，它仅仅是获取资源信息，就像数据库查询一样，不会修改，增加数据，不会影响资源的状态。幂等性(Idempotence): 则指的是无论调用这个URL 多少次，都不会有不同的结果的 HTTP 方法。而在实际过程中，这个规定没有那么严格。例如在一个新闻应用中，新闻站点的头版不断更新，虽然第二次请求会返回不同的一批新闻，该操作仍然被认为是安全的和幂等的，因为它总是返回当前的新闻。</li>
<li>get方法会被浏览器主动的缓存下来，即如果下次还请求相同的数据，就能更快的显示出来。</li>
<li>url是有长度限制的，但是http协议并没有规定，这个限制可以忽略不计，因为也不太可能写满。</li>
<li>get方法只产生一个TCP数据包，浏览器会把请求头和请求数据一并发送出去，服务器响应 200 ok(返回数据)。</li>
</ol>
<h2 id="post方法的特点"><a href="#post方法的特点" class="headerlink" title="post方法的特点"></a>post方法的特点</h2><ol>
<li>因为post方法可能会修改服务器上的数据，所以他时不具备get方法的安全性和幂等性的。</li>
<li>post的请求信息是放在请求数据中的，这也是和get的一个重要区别。</li>
<li>因为请求信息放在请求数据中，所以是没有长度限制的。</li>
<li>最重要的是，post请求会产生两个TCP数据包，浏览器会先将请求头发送给服务器，待服务器响应100 continue之后，浏览器在发送请求数据，然后服务器响应200 ok。</li>
</ol>
<h2 id="关于区别"><a href="#关于区别" class="headerlink" title="关于区别"></a>关于区别</h2><p>实际上，post和get并没有本质上的区别，因为他们本质都是TCP链接，但是由于http协议的规定和浏览器或者服务器的限制，导致他们在应用中的不同。</p>
<h1 id="计算属性和监听器有什么区别？"><a href="#计算属性和监听器有什么区别？" class="headerlink" title="计算属性和监听器有什么区别？"></a>计算属性和监听器有什么区别？</h1><h2 id="计算属性特点以及适用的场景"><a href="#计算属性特点以及适用的场景" class="headerlink" title="计算属性特点以及适用的场景"></a>计算属性特点以及适用的场景</h2><p>为什么要设计computed计算属性呢？因为在设计模板表达式的时候是为了简化计算，但是当业务越多，比如说有一个字符串的反转需求：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example"</span>&gt;</span></span><br><span class="line">  &#123;&#123; message.split('').reverse().join('') &#125;&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>可以看到模板表达式中，冗余且复杂。那么怎么办呢？这时就用到了计算属性computed。</p>
<p>文档中有一句话：处理任何复杂逻辑的运算都应该放在计算属性中。</p>
<p>通过代码理解computed。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"example"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>Original message: "&#123;&#123; message &#125;&#125;"<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span>Computed reversed message: "&#123;&#123; reversedMessage &#125;&#125;"<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> vm = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">  el: <span class="string">'#example'</span>,</span><br><span class="line">  data: &#123;</span><br><span class="line">    message: <span class="string">'Hello'</span></span><br><span class="line">  &#125;,</span><br><span class="line">  computed: &#123;</span><br><span class="line">    <span class="comment">// 计算属性的 getter</span></span><br><span class="line">    reversedMessage: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">      <span class="comment">// `this` 指向 vm 实例</span></span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">this</span>.message.split(<span class="string">''</span>).reverse().join(<span class="string">''</span>)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>可以发现模板表达式中居然是一个函数！那么问题来了，为什么不用methods呢？</p>
<p>这就涉及到computed属性特点了：计算属性是依赖于data里面属性的变化而变化的。而他们又是响应式的，所以只要data不变，那么computed的值也就不变。所以在vue中，computed的值被缓存了下来。只要data不变，不论这个计算属性调用多少次，都会立即返回结果。即只在第一次被调用或者data改变时才会进行计算。</p>
<p>而methods是只要页面被渲染，就会重新进行计算。</p>
<h2 id="watch侦听属性"><a href="#watch侦听属性" class="headerlink" title="watch侦听属性"></a>watch侦听属性</h2><p>这里其实理解这句话就行：计算属性是通过已知的属性可以计算出一个新的属性，并且这个新的属性可以直接使用而不用在data中定义；侦听属性是一个已知的属性通过监测一个或多个已知的属性的变化而改变。</p>
<h1 id="v-for渲染列表的key有什么作用？"><a href="#v-for渲染列表的key有什么作用？" class="headerlink" title="v-for渲染列表的key有什么作用？"></a>v-for渲染列表的key有什么作用？</h1><p>给循环项加上key值后，每一个列都会有自己的key，即唯一标识，那么计算机就能判断出在操作后的列表和之前的列表的不同了（可以知道是哪儿一项的改变）。</p>
<p>这里挖一个坑：明天再来说。</p>
<p>来了。看了官方文档之后总结了一下：</p>
<ol>
<li>key值主要用在Vue的虚拟dom算法上。在新旧节点对比时可以起到辨识的作用。（这里又挖一坑，因为之前看过diff算法）</li>
<li>如果不用key，那么Vue就会尽量使用就地修改/复用相同元素的算法。这就会带来一个bug，就是你以为你删除了a，但是计算机认为你删除了b。</li>
<li>那么当你使用key的时候，他是基于key的变化然后再去重新排列顺序，然后会移除key不存在的值。</li>
<li>在很多子元素又相同的父元素时，必须要使用key，最常见的也就是v-for。</li>
<li>还有一点，尽量避免使用index，即数组的下标做key，因为这可能会出现一个bug，最好是在数组中添加id值作为key值。</li>
</ol>
<h1 id="数据请求在生命周期的哪儿个阶段？"><a href="#数据请求在生命周期的哪儿个阶段？" class="headerlink" title="数据请求在生命周期的哪儿个阶段？"></a>数据请求在生命周期的哪儿个阶段？</h1><p>这道题实际上就是考察对vue生命周期的掌握程度。</p>
<p>通过官方文档就能看出来。废话不多说直接看代码。</p>
<p>这段测试生命周期的代码大致意思就是，当渲染出页面时（即用户能看到页面的时刻起），之前就以及发生了4个函数被调用的事情，分别时beforeCreate，created，beforeMount，mounted。接着通过输入框的双向绑定指令v-model，使得data数据发生改变。当data发生改变时，会调用两个函数，首先data改变之后，立即调用beforeUpdate,当新渲染的页面出来后立即调用updated。接着在updated函数中使用 this.$destroy() 去触发销毁函数，即beforeDestroy和destroyed。</p>
<p>通过调式，这个问题就很显然了，请求数据可以在created、beforMount、mounted中，但是数据请求越早越好没所以在created中请求！</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">	&#123;&#123;x&#125;&#125;</span><br><span class="line">	<span class="tag">&lt;<span class="name">input</span> <span class="attr">v-model</span>=<span class="string">"x"</span> <span class="attr">type</span>=<span class="string">"text"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> app = <span class="keyword">new</span> Vue(&#123;</span><br><span class="line">  el: <span class="string">"#app"</span>,</span><br><span class="line">  data: &#123;</span><br><span class="line">    x: <span class="number">1</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">// beforeCreate 拿不到数据！</span></span><br><span class="line">  beforeCreate: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x) <span class="comment">//undefined</span></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeCreate"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  created: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"created"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  beforeMount: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeMount"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  mounted: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"mounted"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  beforeUpdate: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeUpdate"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  updated: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"updated"</span>)</span><br><span class="line">    <span class="comment">// 测试销毁函数</span></span><br><span class="line">    <span class="comment">// 文档中说的是：当调用vm.$destroy()函数时就执行销毁函数</span></span><br><span class="line">    <span class="comment">// 调用beforeDestroy、destroyed</span></span><br><span class="line">    <span class="keyword">this</span>.$destroy()</span><br><span class="line">  &#125;,</span><br><span class="line">  beforeDestroy: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeDestroy"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">  destroyed: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.x)</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"destroyed"</span>)</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<h1 id="水平居中有哪儿几种方法？"><a href="#水平居中有哪儿几种方法？" class="headerlink" title="水平居中有哪儿几种方法？"></a>水平居中有哪儿几种方法？</h1><p>我一般都是用flex布局，他有两种可以居中的方法，一个是justify-content，另一个是align-items。如果不用flex布局，可以使用margin 0 auto、text-align center，还可以通过定位的方式，最后是grid布局。</p>
<p>这里有时间要好好看看grid布局。先暂时精通flex就好。</p>
<h1 id="flex布局（已精通）"><a href="#flex布局（已精通）" class="headerlink" title="flex布局（已精通）"></a>flex布局（已精通）</h1><h1 id="父盒子中子盒子浮动有什么后果？"><a href="#父盒子中子盒子浮动有什么后果？" class="headerlink" title="父盒子中子盒子浮动有什么后果？"></a>父盒子中子盒子浮动有什么后果？</h1><p>如果没有给父元素设置宽高的话，即父盒子由子盒子撑开，那么就会造成高度的塌陷。因为float会让文档脱离文本流。</p>
<p>如图：</p>
<p><img src="/images/28.png" alt></p>
<p><img src="/images/29.png" alt></p>
<p>那么怎么解决呢？</p>
<ol>
<li>对父元素使用overflow：hidden。那么该元素的内容若超出了给定的宽度和高度属性，那么超出的部分将会被隐藏，不占位。这里又可以引申出一个需求，就是一段文本在超出范围后使用省略号的技巧。</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 这里要注意，需要给文本所在的标签设置！而不是p标签的父元素 */</span></span><br><span class="line">   <span class="selector-class">.son1</span> <span class="selector-tag">p</span> &#123;</span><br><span class="line">     <span class="attribute">overflow</span>: hidden;</span><br><span class="line">     <span class="attribute">white-space</span>: nowrap;</span><br><span class="line">     <span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>通过after伪元素。代码如下(::after用来创建一个伪元素，作为已选中元素的最后一个子元素。通常会配合content属性来为该元素添加装饰内容。这个虚拟元素默认是行内元素。)</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.father</span><span class="selector-pseudo">::after</span>&#123;</span><br><span class="line">	<span class="attribute">content</span>:<span class="string">""</span>;</span><br><span class="line">	<span class="attribute">clear</span>:both;</span><br><span class="line">	<span class="attribute">dasplay</span>:block;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="定位属性有哪儿些？"><a href="#定位属性有哪儿些？" class="headerlink" title="定位属性有哪儿些？"></a>定位属性有哪儿些？</h1><p>总共有五种定位属性，分别是：</p>
<ol>
<li>absolute</li>
<li>relative</li>
<li>fixed</li>
<li>sticky</li>
<li>static(默认的)</li>
</ol>
<p>还有一些需要特点需要记住，这里不展开讲了。也不难，以后复习多看看这块就行。</p>
<h1 id="相对定位是相对什么定位？"><a href="#相对定位是相对什么定位？" class="headerlink" title="相对定位是相对什么定位？"></a>相对定位是相对什么定位？</h1><p>相对定位就是relative，他是相对于自身的正常位置进行定位的，并没有脱离常规流。</p>
<p>还有一点很重要，设置了relative的元素，其后代的absolute都是相对于这个父元素进行的。这也就是常见的子绝父相。</p>
<p>另外的就是，浮动元素进行偏移操作是无效的。但是如果给他设置了relative，就可以进行偏移操作了。</p>
<h1 id="行内元素和行内块元素的区别？"><a href="#行内元素和行内块元素的区别？" class="headerlink" title="行内元素和行内块元素的区别？"></a>行内元素和行内块元素的区别？</h1><p>行内元素就是display:inline    行内块状元素就是display:inline-block</p>
<p>其实可以看出，行内块状元素既有inline的特点，又有block的特点。</p>
<p>行内元素特点：</p>
<ol>
<li>设置宽高无效</li>
<li>对margin仅设置左右方向有效，上下无效；padding设置上下左右都有效，即会撑大空间</li>
<li>不会自动进行换行</li>
</ol>
<p>行内块状元素特点：</p>
<ol>
<li>不自动换行</li>
<li>能够识别宽高</li>
<li>默认排列方式为从左到右</li>
</ol>
<h1 id="行内块元素在同一行显示时有默认空隙，如何解决？"><a href="#行内块元素在同一行显示时有默认空隙，如何解决？" class="headerlink" title="行内块元素在同一行显示时有默认空隙，如何解决？"></a>行内块元素在同一行显示时有默认空隙，如何解决？</h1><p>首先出现问题的原因在于书写html的时候，为了美观然后换行书写造成的</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 会造成默认空隙 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 不会造成默认空隙 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="tag">&lt;<span class="name">button</span>&gt;</span>行内块元素<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>还有几种其他方法，但是都是改变书写的方法，如何通过css改变呢？</p>
<p>在父元素中设置font-size：0即可。</p>
<h1 id="给dom元素绑定事件有哪儿些方法？"><a href="#给dom元素绑定事件有哪儿些方法？" class="headerlink" title="给dom元素绑定事件有哪儿些方法？"></a>给dom元素绑定事件有哪儿些方法？</h1><ol>
<li>直接在html代码中绑定。</li>
<li>在js中通过获取dom元素之后绑定。</li>
<li>使用addEventListener（）可为一个元素绑定多个事件。</li>
</ol>
<h1 id="数组里面有什么遍历方法？es6"><a href="#数组里面有什么遍历方法？es6" class="headerlink" title="数组里面有什么遍历方法？es6"></a>数组里面有什么遍历方法？es6</h1><ol>
<li>for循环</li>
<li>every</li>
<li>some</li>
<li>forEach</li>
<li>map</li>
<li>filter</li>
<li>reduce</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/06/01/vue%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8%E7%9A%84%E4%B8%80%E4%BA%9B%E9%97%AE%E9%A2%98/" rel="prev" title="vue音乐播放器的一些问题">
      <i class="fa fa-chevron-left"></i> vue音乐播放器的一些问题
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/06/07/vue%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96%E7%AC%94%E8%AE%B0/" rel="next" title="ES6模块化笔记以及webpack简单的配置使用">
      ES6模块化笔记以及webpack简单的配置使用 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#vueAPP适配怎么写，用了什么单位？"><span class="nav-number">1.</span> <span class="nav-text">vueAPP适配怎么写，用了什么单位？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#get和post的区别？"><span class="nav-number">2.</span> <span class="nav-text">get和post的区别？</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#http请求报文"><span class="nav-number">2.1.</span> <span class="nav-text">http请求报文</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#get方法的特点"><span class="nav-number">2.2.</span> <span class="nav-text">get方法的特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#post方法的特点"><span class="nav-number">2.3.</span> <span class="nav-text">post方法的特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#关于区别"><span class="nav-number">2.4.</span> <span class="nav-text">关于区别</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#计算属性和监听器有什么区别？"><span class="nav-number">3.</span> <span class="nav-text">计算属性和监听器有什么区别？</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#计算属性特点以及适用的场景"><span class="nav-number">3.1.</span> <span class="nav-text">计算属性特点以及适用的场景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#watch侦听属性"><span class="nav-number">3.2.</span> <span class="nav-text">watch侦听属性</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#v-for渲染列表的key有什么作用？"><span class="nav-number">4.</span> <span class="nav-text">v-for渲染列表的key有什么作用？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#数据请求在生命周期的哪儿个阶段？"><span class="nav-number">5.</span> <span class="nav-text">数据请求在生命周期的哪儿个阶段？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#水平居中有哪儿几种方法？"><span class="nav-number">6.</span> <span class="nav-text">水平居中有哪儿几种方法？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#flex布局（已精通）"><span class="nav-number">7.</span> <span class="nav-text">flex布局（已精通）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#父盒子中子盒子浮动有什么后果？"><span class="nav-number">8.</span> <span class="nav-text">父盒子中子盒子浮动有什么后果？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#定位属性有哪儿些？"><span class="nav-number">9.</span> <span class="nav-text">定位属性有哪儿些？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#相对定位是相对什么定位？"><span class="nav-number">10.</span> <span class="nav-text">相对定位是相对什么定位？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#行内元素和行内块元素的区别？"><span class="nav-number">11.</span> <span class="nav-text">行内元素和行内块元素的区别？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#行内块元素在同一行显示时有默认空隙，如何解决？"><span class="nav-number">12.</span> <span class="nav-text">行内块元素在同一行显示时有默认空隙，如何解决？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#给dom元素绑定事件有哪儿些方法？"><span class="nav-number">13.</span> <span class="nav-text">给dom元素绑定事件有哪儿些方法？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#数组里面有什么遍历方法？es6"><span class="nav-number">14.</span> <span class="nav-text">数组里面有什么遍历方法？es6</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Edison</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">124</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
</div>
  <div class="powered-by">山高水远  一定相见
  </div>
<div></div>
<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">至今已写107.1k字</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
